package com.miao.util.developMode.observerMode;

import org.apache.commons.lang3.StringUtils;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by miao on 2015/4/13.
 */
public class Watcher implements Observer {

    public Watcher(Observable observable) {
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        System.out.println("观察者知道主题状态发生了改变:" + ((Watched) o).getData());
        if (StringUtils.equalsIgnoreCase(((Watched) o).getData(), "start")) {
            System.out.println("开始工作");
        } else if (StringUtils.equalsIgnoreCase(((Watched) o).getData(), "run")) {
            System.out.println("工作中...");
        } else {
            System.out.println("结束工作");
        }
    }
}
